/**
 * @Description: test
 * @Author: Hu Outstanding
 * @Date: 2022/1/12 20:06
 */
package com.aaa.three.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.UUID;

@Data
public class OSSUtil {

    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;
    private String path;


    public String upLoadOSS(MultipartFile file) {

        try {
            String fileName = UUID.randomUUID().toString() + file.getContentType().replace("image/", ".");

            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

            InputStream inputStream = file.getInputStream();

            ossClient.putObject(bucketName, fileName, inputStream);

            ossClient.shutdown();

            return path + fileName;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;


    }
}
